<template>
  <div class="edu-empty">
    <div class="edu-empty__image" :style="[imageStyle]" v-if="showImage">
      <u-image
        v-if="image"
        :src="image"
        :width="imageStyle.width"
        :height="imageStyle.height"
      ></u-image>
      <slot v-else name="image">
        <u-image
          :src="require('@/static/images/empty.png')"
          :width="imageStyle.width"
          :height="imageStyle.height"
        ></u-image>
      </slot>
    </div>
    <div class="edu-empty__description" v-if="showDescription">
      <slot v-if="$slots.description" name="description"></slot>
      <div v-else class="desc">{{ emptyDescription }}</div>
    </div>
    <div v-if="$slots.default" class="edu-empty__bottom">
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    // 图片
    image: {
      type: String,
      default: '',
    },
    // 是否展示图片
    showImage: {
      type: Boolean,
      default: true,
    },
    width: {
      type: [String, Number],
      default: 284,
    },
    height: {
      type: [String, Number],
      default: 211,
    },
    // 描述信息
    description: {
      type: String,
      default: '',
    },
    // 是否展示描述信息
    showDescription: {
      type: Boolean,
      default: true,
    },
  },
  computed: {
    emptyDescription() {
      return this.description || '暂无内容~'
    },
    imageStyle() {
      let style = {}
      style.width = this.$u.addUnit(this.width)
      style.height = this.$u.addUnit(this.height)
      return style
    },
  },
}
</script>

<style lang="scss" scoped>
.edu-empty {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  text-align: center;
  box-sizing: border-box;
  padding: 80rpx 0;
  .edu-empty__description {
    margin-top: 30rpx;
    .desc {
      font-size: 28rpx;
      color: #a4a4a4;
    }
  }
  .edu-empty__bottom {
    margin-top: 40rpx;
  }
}
</style>
